package com.gitee.huanminabc.utils_common.obj;

import org.openjdk.jol.info.ClassLayout;

import java.util.List;
import java.util.Set;

public class ObjSize {

    //获取对象大小
    public static long sizeOf(Object obj) {
        ClassLayout layout = ClassLayout.parseInstance(obj);
        return layout.instanceSize();
    }
    //计算List的大小
    public static long sizeOfList(List list) {
        long size = 0;
        for (Object obj : list) {
            size += sizeOf(obj);
        }
        return size;
    }
    //set
    public static long sizeOfSet(Set set) {
        long size = 0;
        for (Object obj : set) {
            size += sizeOf(obj);
        }
        return size;
    }
}
